//
//  XSThumbnailSelectedViewCollectionViewCell.m
//  AudioVideo
//
//  Created by xueshan1 on 2019/10/28.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import "XSThumbnailSelectedViewCollectionViewCell.h"

@interface XSThumbnailSelectedViewCollectionViewCell ()

@property (nonatomic, copy) NSString *identifier;
@property (nonatomic, assign) PHImageRequestID imageRequestID;

@end

@implementation XSThumbnailSelectedViewCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (IBAction)deleteBtnAction:(id)sender {
    
    if (self.clickDeleteBtnBlock) {
        self.clickDeleteBtnBlock(self.photoModel);
    }
}

- (void)setPhotoModel:(XSPhotoModel *)photoModel{
    _photoModel = photoModel;
   
    if (photoModel.image) {
        self.imageV.image = photoModel.image;
    }else{
        self.identifier = photoModel.asset.localIdentifier;
        self.imageV.image = nil;
        self.imageRequestID =[XSPhotosManager requestImageForAsset:photoModel.asset size:self.imageV.bounds.size progressHandler:nil completion:^(UIImage *image, NSDictionary *info) {
            
            if ([self.identifier isEqualToString:photoModel.asset.localIdentifier]) {
                self.imageV.image = image;
            }
            
            if (![[info objectForKey:PHImageResultIsDegradedKey] boolValue]) {
                self.imageRequestID = -1;
            }
        }];
        
    }
    
    
}


@end
